home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6338 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  55 lines

  1. Path: emerald.tufts.edu!rdorich
  2. From: rdorich@emerald.tufts.edu (Roberto Dorich)
  3. Newsgroups: comp.lang.c
  4. Subject: automatic charrs
  5. Date: 24 Feb 1996 01:19:05 GMT
  6. Organization: Tufts University
  7. Message-ID: <4glp29$dsh@d2.tufts.edu>
  8. NNTP-Posting-Host: emerald.tufts.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hello,
  12.  
  13. Could someone enlighten me, and tell me why the following program runs
  14. just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
  15.  
  16. #include <stdio.h>
  17. char *b() { return "Hello";}
  18.  
  19. main() {
  20.   char *a=b();
  21.  
  22.   a[0]='X';
  23.   printf("--> %s\n",a);
  24. }
  25.  
  26. Esentially, gcc puts out the following assembly code:
  27.  
  28. call b,0
  29. nop
  30. mov 88,%o1        // %o1 = 'X'
  31. stb %o1, [%o0]          // a[0] = %o1
  32.  
  33. And cc spits out the following:
  34.  
  35.         call    b
  36.         nop
  37.         mov     88,%l1
  38.         stb     %l1,[%l0+0]
  39.  
  40. (this assembly code has been optimized by me :-/ )
  41.  
  42. Anyway, there isn't really that much difference... but I get a seg fault
  43. with gcc.  Why?
  44.  
  45. Thanks!
  46.  
  47. Roberto
  48.  
  49. --
  50.  
  51. Roberto Dorich               o       SKI        rdorich@ee.cornell.edu
  52. Electrical Engineering   /=     EXTREME         rdorich@tufts.edu
  53. Cornell University     __/__,               dorich@ptc.com
  54. ----------------------------------------------------------------------
  55.